package com.wty.good.controller;

/**
 * @Author:wangtianyu
 * @Date：Created on 2020/4/23 0023 13:02
 */

import com.wty.commons.result.Result;
import com.wty.good.pojo.CategoryWty;
import com.wty.good.service.CategoryServiceWty;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类别
 */
@RestController
@RequestMapping("categories")
public class CategoryControllerWty {

    @Autowired
    private CategoryServiceWty categoryService;

    /*添加商品类别*/
    @ApiOperation(value = "添加商品类别")
    @ApiImplicitParam(name = "category", dataType = "CategoryWty", dataTypeClass = CategoryWty.class)
    @PostMapping
    public Result<CategoryWty> addCategory(@RequestBody CategoryWty category) throws Exception {
        category = categoryService.addCategory(category);
        return Result.OK(category);
    }

    /*查询*/
    @ApiOperation(value = "查看所有商品类别")
    @GetMapping
    private Result<List<CategoryWty>> selectList()throws Exception{
        List<CategoryWty> categories = categoryService.selectList();
        return Result.OK(categories);
    }

}
